package cn.zyq.ykb.service.config.impl;

import cn.zyq.ykb.system.common.BaseService;
import com.github.pagehelper.PageHelper;
import cn.zyq.ykb.system.ry.util.SecurityUtils;
import cn.zyq.ykb.mapper.config.ConfigHelpMapper;
import cn.zyq.ykb.beans.config.ConfigHelp;
import cn.zyq.ykb.service.config.ConfigHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.zyq.ykb.system.common.PageParam;
import com.github.pagehelper.PageInfo;


import java.time.LocalDateTime;
import java.util.UUID;
import java.util.List;

/**
 * 配置-帮助手册Service业务层处理
 *
 * @author SystemAuth
 * @date 2023-11-27
 */
@Service
public class ConfigHelpServiceImpl  extends BaseService implements ConfigHelpService {

    @Autowired
    private ConfigHelpMapper configHelpMapper;

    /**
     * 查询配置-帮助手册
     *
     * @param configHelpID 配置-帮助手册主键
     * @return 配置-帮助手册
     */
    @Override
    public ConfigHelp selectConfigHelpByConfigHelpID(Integer configHelpID) {
        ConfigHelp configHelp = configHelpMapper.selectByPrimaryKey(configHelpID);
        if (configHelp.getDeleted() == 1) {
            return null;
        }
        return configHelp;
    }

    /**
     * 查询配置-帮助手册
     *
     * @param serviceID 业务ID
     * @return 配置-帮助手册
     */
    @Override
    public ConfigHelp selectConfigHelpByServiceID(String serviceID) {
        ConfigHelp param = new ConfigHelp();
        param.setDeleted(0);
        param.setServiceID(serviceID);
        return this.configHelpMapper.selectOne(param);
    }

    /**
     * 查询配置-帮助手册列表
     *
     * @param pageParam
     * @return 配置-帮助手册
     */
    @Override
    public PageInfo<ConfigHelp> selectConfigHelpList(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        pageParam.getKv().put("deleted", 0);
        List<ConfigHelp> list = this.configHelpMapper.list(pageParam.getKv());
        return new PageInfo<>(list);
    }

    /**
     * 查询配置-帮助手册列表
     *
     * @param pageParam
     * @return 配置-帮助手册
     */
    @Override
    public List<ConfigHelp> selectConfigHelpAllList(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        pageParam.getKv().put("deleted", 0);
        return this.configHelpMapper.list(pageParam.getKv());
    }
    /**
     * 新增配置-帮助手册
     *
     * @param param 配置-帮助手册
     * @return 结果
     */
    @Override
    public int insertConfigHelp(ConfigHelp param) {
        this.setCreateBaseData(param, SecurityUtils.getLoginUser().getSysAdmin());
        return this.configHelpMapper.insertSelective(param);
    }

    /**
     * 修改配置-帮助手册
     *
     * @param param 配置-帮助手册
     * @return 结果
     */
    @Override
    public int updateConfigHelp(ConfigHelp param) {
        this.setUpdateBaseData(param, SecurityUtils.getLoginUser().getSysAdmin());
        return this.configHelpMapper.updateByPrimaryKeySelective(param);
    }

    /**
     * 批量删除配置-帮助手册
     *
     * @param configHelpIDs 需要删除的配置-帮助手册主键
     * @return 结果
     */
    @Override
    public int deleteConfigHelpByConfigHelpIDs(Integer[] configHelpIDs) {
        int i = 0;
        for (Integer configHelpID : configHelpIDs) {
            i += this.deleteConfigHelpByConfigHelpID(configHelpID);
        }
        return i;
    }

    /**
     * 删除配置-帮助手册信息
     *
     * @param configHelpID 配置-帮助手册主键
     * @return 结果
     */
    @Override
    public int deleteConfigHelpByConfigHelpID(Integer configHelpID) {
        ConfigHelp configHelp = this.selectConfigHelpByConfigHelpID(configHelpID);
        if (configHelp == null) {
            return 0;
        } else {
            ConfigHelp storeInfo = new ConfigHelp();
            storeInfo.setConfigHelpID(configHelpID);
            storeInfo.setDeleted(1);
            storeInfo.setUpdateBy(SecurityUtils.getSysAdminID());
            storeInfo.setUpdateTime(LocalDateTime.now());
            this.configHelpMapper.updateByPrimaryKeySelective(storeInfo);
            return 1;
        }
    }
}
